/*
 * Created on 2006-8-2 上午07:25:01
 */
package cn.com.sbell.vss.csg.heartbeat;

import java.util.Date;

import cn.com.sbell.vss.csg.vsclient.util.CSGConfiguration;

public class HeartBeatMessage {
	
	public final static int HEARTBEAT = 0;
	public final static int REGISTER = 1;
	
	private int messageType;
	private boolean needAcknowledge;
	private int period;
	private int port;
	private String serverId;
	private String serverIp;
	private String serverName;
	private String originalIp;
	private int originalPort;
	private String accessPassword;
	private String serverType;
	private final long timestamp = System.currentTimeMillis();
	
	public HeartBeatMessage(){}
	
	public boolean equals(Object object){
		if(object == null) 
			return false;
		if(this == object) 
			return true;
		if(!(object instanceof HeartBeatMessage))
			return false;
		HeartBeatMessage msg = (HeartBeatMessage)object;
		return this.serverId==null ? msg.serverId==null : this.serverId.equals(msg.serverId);
	}
	
	public int hashCode(){
		return this.serverId.hashCode();
	}
	
	public Date getExpireTime(){
		return new Date(timestamp + period * 1000 * CSGConfiguration.COMMON_HEARTBEAT_ATTEMP_TIMES+CSGConfiguration.COMMON_HEARTBEAT_DELAY*1000);
	}
	
	public int getPeriod() {
		return period;
	}
	public int getPort() {
		return port;
	}
	public String getServerId() {
		return serverId;
	}
	public String getServerIp() {
		return serverIp;
	}
	public String getServerName() {
		return serverName;
	}
	
	public int getMessageType() {
		return messageType;
	}
	public void setMessageType(int messageType) {
		this.messageType = messageType;
	}
	
	public boolean isNeedAcknowledge() {
		return needAcknowledge;
	}
	public void setNeedAcknowledge(boolean needAcknowledge) {
		this.needAcknowledge = needAcknowledge;
	}
	public void setPeriod(int period) {
		this.period = period;
	}
	public void setPort(int port) {
		this.port = port;
	}
	
	public void setServerId(String serverId) {
		this.serverId = serverId;
	}
	
	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}
	
	public void setServerName(String serverName) {
		this.serverName = serverName;
	}
	
	/**
	 * @return the originalIp
	 */
	public String getOriginalIp() {
		return originalIp;
	}

	/**
	 * @param originalIp the originalIp to set
	 */
	public void setOriginalIp(String originalIp) {
		this.originalIp = originalIp;
	}

	/**
	 * @return the originalPort
	 */
	public int getOriginalPort() {
		return originalPort;
	}

	/**
	 * @param originalPort the originalPort to set
	 */
	public void setOriginalPort(int originalPort) {
		this.originalPort = originalPort;
	}
	
	public String getAccessPassword() {
		return accessPassword;
	}

	public void setAccessPassword(String accessPassword) {
		this.accessPassword = accessPassword;
	}

	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("\nNEEDACKNOWLEDGE=");
		sb.append(this.needAcknowledge);
		sb.append("\nSERVERNAME=");
		sb.append(this.serverName);
		sb.append("\nSERVERGUID=");
		sb.append(this.serverId);
		sb.append("\nSERVERIP=");
		sb.append(this.serverIp);
		sb.append("\nPORT=");
		sb.append(this.port);
		sb.append("\nPERIOD=");
		sb.append(this.period);
		sb.append("\noriginalIp=");
		sb.append(this.originalIp);
		sb.append("\noriginalPort=");
		sb.append(this.originalPort);
		sb.append("\nAccessPassword=");
		sb.append(this.accessPassword);
		sb.append("\nserverType=");
		sb.append(this.serverType);
		return sb.toString();
	}

	public String getServerType() {
		return serverType;
	}

	public void setServerType(String serverType) {
		this.serverType = serverType;
	}
}
